﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;

namespace TipokHostManager
{
    public class HostServices
    {
        MonitorLocalService sm = null;

        public void Start()
        {
            sm = new MonitorLocalService();
            sm.ServerInstallEvent += (send, even) => SendMessage(send, even);
            sm.ServerUnInstallEvent += (send, even) => SendMessage(send, even);
            sm.ServerStartEvent += (send, even) => SendMessage(send, even);
            sm.ServerStopEvent += (send, even) => SendMessage(send, even);
            sm.ServerOhterThingEvent += (send, even) => SendMessage(send, even);
            sm.Start();
            InitializerWCFService.Start();
        }

        public void Stop()
        {
            InitializerWCFService.Stop();
            sm.Stop();
            sm = null;
        }

        void SendMessage(object send, Model.NoftifyAdminEventArgs even)
        {
            string classValue = ((ManagementBaseObject)send).SystemProperties["__Class"].Value.ToString();
           System.Console.WriteLine(">>>" + classValue + "| serviceName=" + even.Model.ServiceName + "| serviceStatus=" + even.Model.State);
        }
    }
}
